package algorithm;

import java.io.*;
import java.util.Arrays;

/**
 * Created by GodRUI on 2021/8/24 11:49
 *
 * 读取文件 并排序
 */
public class ReadFileBubbleSort {

    public static void main(String[] args) throws Exception {

        String filepath ="data/test.txt";
        String filepath1 ="data/test1.txt";

        BufferedReader br = new BufferedReader(new FileReader(filepath));

        BufferedWriter bw = new BufferedWriter(new FileWriter(filepath1));

        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = br.readLine())!=null){
            System.out.println(line);
            sb.append(line);

            bw.write(line);
        }

        br.close();
        bw.close();

        System.out.println(sb);

        String[] split = sb.toString().split(",");

        for (int i = 0; i < split.length - 1; i++) {
            for (int j = 0; j < split.length - i - 1; j++) {
                int l = Integer.parseInt(split[j]);
                int r = Integer.parseInt(split[j+1]);

                if (l>r){
                    split[j] = r+"";
                    split[j+1] = l +"";
                }
            }
        }

        System.out.println(Arrays.toString(split));


    }

}
